package ru.pb.game.network.engine.client.packets.receivable;

import java.util.Arrays;

import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.opcode_3856_ACK;
import ru.pb.game.objects.model.players.Player;
import ru.pb.game.objects.model.room.Room;
import ru.pb.game.objects.storage.ObjectsStorage;

/**
 * Типа, воскрешает чара.
 * 
 * @author Felixx
 */
public class opcode_3855_REQ extends FromClientToGameServerPacket
{
	private int _first, _second, _third, _fourth, _fifth, _id; // выбранные пушки в данных слотах
	private int _red, _blue, _head, _beret, _dino, _UNK;

	@Override
	public void readImpl()
	{
		// _log.info("buffer count: " + _buf.remaining());
		readH();
		_first = readD();
		_second = readD();
		_third = readD();
		_fourth = readD();
		_fifth = readD();
		_id = readD();
		_red = readD();
		_blue = readD();
		_head = readD();
		_beret = readD();
		_dino = readD();
		_UNK = readC();

		//_log.info("first: " + _first);
		//_log.info("second: " + _second);
		//_log.info("third: " + _third);
		//_log.info("fourth: " + _fourth);
		//_log.info("fifth: " + _fifth);
		//_log.info("id: " + _id);

		//_log.info("red: " + _red);
		//_log.info("blue: " + _blue);
		//_log.info("head: " + _head);
		//_log.info("beret: " + _beret);
		//_log.info("dino: " + _dino);
		//_log.info("UNK: " + _UNK);

		//if(_buf.hasRemaining())
		//{
		//	_log.info("!!!!!!!!!!!!!  ===== REMAINING: " + Arrays.toString(readB(_buf.remaining())));
		//}
	}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			Room r = p.getRoom();
			if(r != null)
			{
				Player member = null;
				for(int objId : r.getAllPlayers().toArray())
				{
					member = ObjectsStorage.getInstance().getPlayer(objId);
					if(member != null)
					{
						member.sendPacket(new opcode_3856_ACK(new ResInfo(_first, _second, _third, _fourth, _fifth, _id, _red, _blue, _head, _beret, _dino), p));
					}
				}
			}
		}
	}

	public class ResInfo
	{
		public int $first, $second, $third, $fourth, $fifth, $id;
		public int $red, $blue, $head, $beret, $dino;

		public ResInfo(int first, int second, int third, int fourth, int fifth, int id, int red, int blue, int head, int beret, int dino)
		{
			$first = first;
			$second = second;
			$third = third;
			$fourth = fourth;
			$fifth = fifth;
			$id = id;
			$red = red;
			$blue = blue;
			$head = head;
			$beret = beret;
			$dino = dino;
		}
	}
}